// pages/index/index.js

Page({
  data:{
      userInfo:null
  },
   //分享功能
   onShareAppMessage:function(){
    return {
      title: '油菜花',
      desc: '油菜花',
      path: '/page/index/index'
    }
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    console.log(getApp().globalData.userData);
    this.setData({"userInfo": getApp().globalData.userData});
  },
  
  onReady:function(){
    // 页面渲染完成
   
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  formSubmit:function(e){
    //通过ajax保存数据然后返回 
    var self = this;
    console.log( e.detail.value);
    wx.request({
      //url: getApp().globalData.server + "/user/login.do",
      url: getApp().globalData.server + "/wx_user/register.do",
      method:'POST',
      //'{"searchText": \"'+e.detail.value + '","pageNum":1,"pageSize":20}',
      data: '{"wxUsername\":"' + e.detail.value.userName + 
      '","nickname":\"' + e.detail.value.nickName + 
      '","gender":\"' + e.detail.value.sex+ 
      '","mobile":\"' + e.detail.value.telephone + 
      '","school":\"' + e.detail.value.school + 
      '","originplace":\"' + e.detail.value.originPlace +
      '","idcard":\"' + e.detail.value.idCard+'"}',
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        if (res.data.status != 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else {
          //console.log(requestObj);
          console.log(res.data);
          //状态的设置
          
          getApp().globalData.hasLogin = true;
          //console.log(userInfo);
          //注册成功的同时立即登陆，那么这里改变登陆状态和用户信息是否完整状态
          var pages = getCurrentPages();
          var currPage = pages[pages.length - 1];   //当前页面
          var prevPage = pages[pages.length - 2];  //上一个页面
          prevPage.setData({ userDataSave: true });
          prevPage.setData({ isFull: true }); //设置之前判断用户数据是否完整
          wx.navigateBack();

        }

      },
      fail: function () {
        wx.showToast({
          title: "登陆失败",
          icon: 'none',
          duration: 1000,
          mask: true
        })
      }
    })
   
  }
})